#ifndef _acceptor_dragonball_
#define _acceptor_dragonball_

#include "acceptor.h"
#include "igslib_iserial_manager.h"
#include "protocol_DragonBall.h"

namespace igslib
{
    class acceptor_Grgn:public CAcceptor
    { 
        protected:
            static int ID;
			int LocID;
            char ctrl[7]={0};
        public:

            acceptor_Grgn()
            {
                ID++;
				LocID=ID;
                spi = nullptr;
                ctrl[0]=1; 
            }

            ~acceptor_Grgn()
			{
				if(ID>-1)
				 ID--;
			}
            void SetSPI(ISpi* value) { spi = value; }
            ErrorState GetErrorState() 
            { 
                Protocol_DragonBall* tmp = (Protocol_DragonBall*)(spi);
                auto st = tmp-> GetAcceptorSat(LocID);
                if(st)
                    es=ErrorState::Jammed;
                else
                    es=ErrorState::None;
                return es; 	  
            } 
            float GetValue()
            {
                Protocol_DragonBall* tmp = (Protocol_DragonBall*)(spi);
                auto nv = tmp-> GetAcceptorNV(LocID);
                value += nv;
                return value;
            }

            void SetConfirmRange(const float& min,const float& max) 
            { 

                if(min<0 || max>255)
                    throw_igslib_exception("acceptor ConfirmRange Setting over rage");
                confirm = std::make_pair(min,max);
                ctrl[4]=min;
                ctrl[5]=max;
                Protocol_DragonBall* tmp = (Protocol_DragonBall*)(spi);
                tmp-> SetupAcceptor(LocID,ctrl);

            }
            void SetJammedTime(const float& value) 
            { 
                if(value<50 || value>255)
                    throw_igslib_exception("acceptor JammedTime Setting over rage");
                jt = value; 
                ctrl[6]=value;
                Protocol_DragonBall* tmp = (Protocol_DragonBall*)(spi);
                tmp-> SetupAcceptor(LocID,ctrl);
            } 
            void SetHighActive(const bool& value) 
            { 
                ha = value; 
                if( value==true )
                    ctrl[1]=1;
                else
                    ctrl[1]=0;
                Protocol_DragonBall* tmp = (Protocol_DragonBall*)(spi);
                tmp-> SetupAcceptor(LocID,ctrl);

            }

            void SetInhibitiveState(const bool& value  ) 
            { 
                ihs = value;
                Protocol_DragonBall* tmp = (Protocol_DragonBall*)(spi);
                if(value == true)
                    tmp-> SetAcceptor(LocID, 1 ,"Inhibit");
                else
                    tmp-> SetAcceptor(LocID, 0 , "Inhibit");		
            }

            void SetGPIO(IGPIO* value,IGPIO* value1) 
            { 
                gpio = value; 
                gpio_inhibt = value1;

                if(!gpio )
                    throw_igslib_exception("acceptor GPIO is NULL");			
                ctrl[2]=(char)gpio->GetNumber();
                if(gpio_inhibt)
                    ctrl[3]= (char)gpio_inhibt->GetNumber();
                Protocol_DragonBall* tmp = (Protocol_DragonBall*)(spi);
                tmp-> SetupAcceptor(LocID,ctrl);
            }	 

            void ClearError() 	
            { 
                Protocol_DragonBall* tmp = (Protocol_DragonBall*)(spi);
                if(value == true)
                    tmp-> SetAcceptor(LocID, 1 ,"ClrE");	  
            }  



    };
    int acceptor_Grgn::ID = -1;
};

#endif
